﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace TauschFormat2
{
	/// <summary>
	/// Interaktionslogik für Wesen.xaml
	/// </summary>
	public partial class Wesen : Window
	{
        PokeDataDataSet pkData = new PokeDataDataSet();
        PokeDataDataSetTableAdapters.WesenTableAdapter pkTableAdapter = new PokeDataDataSetTableAdapters.WesenTableAdapter();

		public Wesen()
		{
			this.InitializeComponent();
			
			// Fügen Sie Code, der bei der Objekterstellung erforderlich ist, unter diesem Punkt ein.
		}

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            pkTableAdapter.Fill(pkData.Wesen);
            foreach (DataRow row in pkData.Wesen)
            {
                txtWesen.Text += row[0].ToString() + "\r\n";
            }
        }

        private void bttnOK_Click(object sender, RoutedEventArgs e)
        {
            pkTableAdapter.Update(pkData.Wesen);
            var x = from r in pkData.Wesen select r.id;
            foreach (int r in (EnumerableRowCollection<int>)x)
            {
                pkTableAdapter.Delete(r);
            }
            if (txtWesen.Text != String.Empty)
            {
                pkTableAdapter.Update(pkData.Wesen);
                for (int i = 0; i < txtWesen.LineCount; i++)
                {
                    pkData.Wesen.AddWesenRow(txtWesen.GetLineText(i).Replace("\r\n", ""));
                }
                pkTableAdapter.Update(pkData.Wesen);
            }
            this.Close();
        }
	}
}